/*
 * Created on 2005/4/12
 *
 */
package com.erp.app.report.genericInquiry.inquiryMaster.beans;

import java.rmi.RemoteException;
import java.sql.SQLException;
import java.util.Collection;

import com.erp.app.common.ProjectConstants;
import com.erp.app.report.genericInquiry.inquiryMaster.dao.GenericInquirySearchCriteria;
import com.erp.app.report.genericInquiry.inquiryMaster.ejb.GenericInquiryMasterManagerHome;
import com.erp.app.report.genericInquiry.inquiryMaster.ejb.GenericInquiryMasterManagerRemote;
import com.erp.framework.exceptions.FindRecordException;
import com.erp.framework.model.dao.ServiceLocator;
import com.erp.framework.model.delegate.SimpleSearchMaintStyleDelegate;
import com.erp.framework.model.ejb.SimpleSearchMaintStyleRemote;
import com.erp.framework.util.logger.Logger;

public class GenericInquiryMasterDelegate extends SimpleSearchMaintStyleDelegate {
    private SimpleSearchMaintStyleRemote contr = null;

    protected SimpleSearchMaintStyleRemote getMasterManager() {

        if (this.contr == null) {
            try {
                GenericInquiryMasterManagerHome home = null;
                home = (GenericInquiryMasterManagerHome) ServiceLocator.getInstance().getHome(ProjectConstants.EJB_GENERIC_INQUIRY, GenericInquiryMasterManagerHome.class);
                this.contr = home.create();
            } catch (java.lang.reflect.UndeclaredThrowableException ue) {
                Logger.logExceptions(this, ue);
                Logger.error(this, "getMasterManager(), error: " + ue.getUndeclaredThrowable());
            } catch (Exception e) {
                Logger.logExceptions(this, e);
            }
        }
        return this.contr;
    }

    public GenericInquiryMasterVO initialize(String inquiryType, String loginUserCode, String lang) throws FindRecordException, RemoteException {
        GenericInquiryMasterManagerRemote remote = (GenericInquiryMasterManagerRemote)getMasterManager();

        GenericInquiryMasterVO vo = remote.initialize(inquiryType, loginUserCode, lang);

        return vo;
    }

    public Collection getDefaultCriteriaValues(Collection queries, String loginUserCode) throws FindRecordException, SQLException, RemoteException {
        GenericInquiryMasterManagerRemote remote = (GenericInquiryMasterManagerRemote)getMasterManager();

        return remote.getDefaultCriteriaValues(queries, loginUserCode);
    }

    public GenericInquiryMasterVO generate(GenericInquirySearchCriteria criteria, String loginUserCode) throws Exception, RemoteException {
        GenericInquiryMasterManagerRemote remote = (GenericInquiryMasterManagerRemote)getMasterManager();

        return remote.generate(criteria, loginUserCode);
    }
}
